'use strict';

const Controller = require('egg').Controller;

class UserRegisterController extends Controller {
  async index() {
    const { ctx } = this;
    var {userName , pwd } = ctx.request.body
    var db = this.app.mongodb

    var res =await db.collection("user").find({userName}).toArray();

    if (res.length) {
      ctx.body = {
        res:false,
        msg:"用户名已被注册"
      }
    }else{
      var res = await db.collection("user").insertOne({userName,pwd})
      ctx.body = {
        res:true,
        msg:"注册成功"
      }
    }
  }
}

module.exports = UserRegisterController;
